package plugin.lombok;

import lombok.Cleanup;

import java.io.*;

/**
 * 作用于局部变量，用来关闭资源，通过注解来生成finally里面的关闭资源语句
 * Created by yangliwei on 2017/11/9.
 */
public class CleanupTest {
    public static void main(String[] args) throws java.io.IOException {
        @Cleanup InputStream in = new FileInputStream("D:\\ideaProject\\javaStudy\\out.txt");
        @Cleanup OutputStream out = new FileOutputStream("D:\\ideaProject\\javaStudy\\out.txt");
    }
}

/**
 * output:

 FileInputStream in = new FileInputStream("D:\\ideaProject\\javaStudy\\out.txt");

 try {
 FileOutputStream out = new FileOutputStream("D:\\ideaProject\\javaStudy\\out.txt");
 if(Collections.singletonList(out).get(0) != null) {
 out.close();
 }
 } finally {
 if(Collections.singletonList(in).get(0) != null) {
 in.close();
 }

 }


 */